package com.joven.product.api.business.service.impl;

import com.joven.infra.common.model.PageResult;
import com.joven.product.api.business.client.ProductClient;
import com.joven.product.api.business.client.model.ProductCreateCmd;
import com.joven.product.api.business.client.model.ProductEditCmd;
import com.joven.product.api.business.factory.ProductFactory;
import com.joven.product.api.business.service.ProductService;
import com.joven.product.api.business.service.dto.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品Service实现
 *
 * @author Joven
 * @date 2022-01-06 18:21:27
 */
@Slf4j
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductFactory factory;
    @Autowired
    private ProductClient productClient;

    /**
     * 新建商品
     *
     * @param createDTO
     * @return
     */
    @Override
    public boolean create(ProductCreateDTO createDTO) {
        ProductCreateCmd cmd = factory.build(createDTO);
        return productClient.create(cmd);
    }

    /**
     * 编辑商品
     *
     * @param editDTO
     * @return
     */
    @Override
    public boolean edit(ProductEditDTO editDTO) {
        ProductEditCmd cmd = factory.build(editDTO);
        return productClient.edit(cmd);
    }

    /**
     * 分页查询
     *
     * @param pageQuery
     * @return
     */
    @Override
    public PageResult<ProductDTO> getByPage(ProductPageQueryDTO pageQuery) {
        return factory.getByPage(pageQuery);
    }

    /**
     * 根据id查询详情
     *
     * @param id
     * @return
     */
    @Override
    public ProductDetailDTO getDetailById(Long id) {
        return factory.getDetailById(id);
    }
}
